<?php
//后台管理
class IndexAction extends OauthAction
{

    public function _initialize()
    {
        parent::_initialize();
    }

    public function login(){
        if(IS_POST){
            $data = $_POST;
            !empty($data['user_name']) or $this->error(L('EMPTY_USER_NAME'));
            !empty($data['password']) or $this->error(L('EMPTY_PASSWORD'));
            md5($data['verify_code']) == session('verify') or $this->error(L('VERIFY_ERROR'));

            $_map['user_name'] = $data['user_name'];
            $info = self::getAuthinfo($_map);
            !empty($info) or $this->error(L('USER_NAME_ERROR'));
            $info['password'] == md5($data['password']) or $this->error(L('PASSWORD_ERROR'));
            self::saveAccessList($info['manager_id']);
            $_SESSION['manager_id'] = $info['manager_id'];
            $_SESSION['real_name'] = $info['real_name'];
            $this->success('');
        }
        $this->display();
    }

    public function freshVerify(){
        import("ORG.Util.Image");
        Image::buildImageVerify(4, 1, 'png', '60', '30');
    }

    //退出登录
    public function lgout(){
        session_unset();
        session_destroy();
        redirect(U('/cpanel/index/login'));
    }
}